﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_ListPreviousDailyWord')
BEGIN
    PRINT 'Dropping Procedure proc_cm_ListPreviousDailyWord'
    DROP  Procedure  proc_cm_ListPreviousDailyWord
END
GO

PRINT 'Creating Procedure proc_cm_ListPreviousDailyWord'
GO

CREATE PROCEDURE [dbo].[proc_cm_ListPreviousDailyWord]
	@pHtmlPageId [uniqueidentifier]
AS
BEGIN
	SET NOCOUNT ON

	SELECT 
		[dailyword_id]
		,[html_page_id]
		,[weeknum_id]
		,[week_start_dt]
		,[week_end_dt]
		,[published_ind]
		,[assignment_monday_txt]
		,[assignment_tuesday_txt]
		,[assignment_wednesday_txt]
		,[assignment_thursday_txt] 
		,[assignment_friday_txt] 
		,[assignment_saturday_txt] 
		,[assignment_sunday_txt] 
	FROM 
		[dbo].[tbl_dailyword] (NOLOCK)
	WHERE
		[html_page_id] = @pHtmlPageId
		AND week_end_dt < GETDATE()
	ORDER BY
		[weeknum_id] ASC
END
GO

GRANT EXEC ON dbo.proc_cm_ListPreviousDailyWord TO PUBLIC
GO

